﻿using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lamex.mIE.Calculate
{
    public class LGC_VAL_BOM_D47
    {
        public static DataTable LGC_VAL_BOM_D47_VALUE(string DWG_No, string Part_No, string Process_Code, string WORKTIME_LOGIC_CODE, DataTable dtBOM)
        {
            string errorMsg = DWG_No + Part_No + Process_Code;
            try
            {
                //适用物料表
                DataTable dtBom_NECESSARY = Common.GetCommon.GetBOM_NECESSARY();
                //BOM表与适用物料表的交集
                DataTable dtcontrast = new DataTable();
                dtcontrast = Common.GetBOM_Logic.DataTableContrast(dtBOM.Select("MATERIAL_NO='" + Part_No + "'").Length > 0 ?
                    dtBOM.Select("MATERIAL_NO='" + Part_No + "'").CopyToDataTable() : null,
                    dtBom_NECESSARY);
                //获取该工序的所有特征名称
                DataTable dtFeature_Name = Common.GetCommon.GetFEATURE_NAME(Process_Code);

                DataTable dtFeature_List = Common.GetTable.GetTable_Feature();
                for (int i = 0; i < dtFeature_Name.Rows.Count; i++)
                {
                    DataRow dr = dtFeature_List.NewRow();
                    dr["DWG_NO"] = DWG_No;
                    dr["PART_NO"] = Part_No;
                    dr["PROCESS_CODE"] = Process_Code;
                    dr["FEATURE_NAME"] = dtFeature_Name.Rows[i]["FEATURE_NAME"].ToString();
                    dr["FEAT_VALUE"] = Common.GetBOM_Logic.D47_V(Part_No,
                        dtFeature_Name.Rows[i]["FEATURE_NAME"].ToString(),
                        dtBOM,
                        dtcontrast,
                        dtBom_NECESSARY);
                    dr["LABOR_VALUE"] = Calculate.LGC_TIM_VTA.LGC_TIM_VTA_VALUE(DWG_No, Part_No, dtFeature_Name.Rows[i]["FEATURE_NAME"].ToString(), "", Convert.ToDouble(dr["FEAT_VALUE"]));//根据特征定义表工时字段计算
                    dr["UPDATE_TIME"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                    dr["UPDATE_USER"] = Lamex.Common.Loginer.CurrentUser.AccountName;
                    dtFeature_List.Rows.Add(dr);
                }
                return dtFeature_List;
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(errorMsg + ex.Message);
                return null;
            }
        }
    }
}
